﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    Layout = null;

    //公式部分
    List<dynamic> 工位周转率 = new List<dynamic>();
    List<dynamic> 生产利用率 = new List<dynamic>();
    List<dynamic> 准时交车率 = new List<dynamic>();
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {
        var 当月考核目标 = Model.StandardConfigs.Where(o=>o.Month.Year==dt.Year && o.Month.Month==dt.Month).FirstOrDefault();
        if(当月考核目标==null)
        {
            当月考核目标 =  new  S4Store.Domain.AfterSaleKpi.MonthStandardConfig();
        }

        工位周转率.Add(new
        {
            时间 = dt,
            工位周转率目标 = 当月考核目标.工位周转率目标,
            实际工位周转率 = Model.工位周转率(Model.BarModel.SearchSellerId ?? 0, dt.Year, dt.Month)
        });

        生产利用率.Add(new
        {
            时间 = dt,
            生产利用率目标 = 当月考核目标.生产利用率目标,
            实际生产利用率 = (Model.生产利用率(Model.BarModel.SearchSellerId ?? 0, dt.Year, dt.Month)*100)
        });

        准时交车率.Add(new
        {
            时间 = dt,
            准时交车率目标 = 当月考核目标.准时交车率目标,
            实际准时交车率 = Model.GetZSJCL(Model.BarModel.SearchSellerId ?? 0, dt.Year, dt.Month)
        });
        
    }
    
    //图标部分
    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.IsRate = false;
    ChartModel.YAxis = "工位周转率";

    foreach (var item in 工位周转率.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "工位周转率目标";
    foreach (var item in 工位周转率)
    {
        series.Data.Add(item.工位周转率目标);
    }
    ChartModel.Serieses.Add(series);
    
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "实际工位周转率";
    foreach (var item in 工位周转率)
    {
        series1.Data.Add(item.实际工位周转率);
    }
    ChartModel.Serieses.Add(series1);


    //2
    S4Store.Models.Chart.Line ChartModel1 = new S4Store.Models.Chart.Line();
    ChartModel1.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel1.IsRate = true;
    ChartModel1.YAxis = "生产利用率";

    foreach (var item in 生产利用率.GroupBy(o => o.时间))
    {
        ChartModel1.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }

    S4Store.Models.Chart.ChartSeries series11 = new S4Store.Models.Chart.ChartSeries();
    series11.Name = "生产利用率目标";
    foreach (var item in 生产利用率)
    {
        series11.Data.Add(item.生产利用率目标);
    }
    ChartModel1.Serieses.Add(series11);

    S4Store.Models.Chart.ChartSeries series12 = new S4Store.Models.Chart.ChartSeries();
    series12.Name = "实际生产利用率";
    foreach (var item in 生产利用率)
    {
        series12.Data.Add(item.实际生产利用率);
    }
    ChartModel1.Serieses.Add(series12);



    
    
    //3
    S4Store.Models.Chart.Line ChartModel3 = new S4Store.Models.Chart.Line();
    ChartModel3.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel3.YAxis = "准时交车率";

    foreach (var item in 准时交车率.GroupBy(o => o.时间))
    {
        ChartModel3.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series31 = new S4Store.Models.Chart.ChartSeries();
    series31.Name = "准时交车率目标";
    foreach (var item in 准时交车率)
    {
        series31.Data.Add(item.准时交车率目标);
    }
    ChartModel3.Serieses.Add(series31);

    S4Store.Models.Chart.ChartSeries series32 = new S4Store.Models.Chart.ChartSeries();
    series32.Name = "实际准时交车率";
    foreach (var item in 准时交车率)
    {
        series32.Data.Add(item.实际准时交车率);
    }
    ChartModel3.Serieses.Add(series32);

<div style="height:100%; overflow:auto">
@Html.Action("ReportBar", "Common", Model.BarModel)
@*<div class="pagetitle">@(carbrandname)入厂台次过程KPI历史数据查询</div>*@
<div class="pageContent">
	
	<div class="tabs" currentIndex="0" eventType="click">
		<div class="tabsHeader">
			<div class="tabsHeaderContent">
				<ul>
					<li><a href="javascript:;"><span>工位周转率</span></a></li>
					<li><a href="javascript:;"><span>生产利用率</span></a></li>
					<li><a href="javascript:;"><span>准时交车率</span></a></li>
				</ul>
			</div>
		</div>
		<div class="tabsContent" >
			<div>
            @Html.Partial("../Chart/Line", ChartModel)
			</div>
			<div>
            @Html.Partial("../Chart/Line", ChartModel1)
			</div>
            <div>
            @Html.Partial("../Chart/Line", ChartModel3)
			</div>
		</div>
		<div class="tabsFooter">
			<div class="tabsFooterContent"></div>
		</div>
	</div>
</div>

</div>
}
